package com.freedom.controller.w.core;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.freedom.bean.core.SysMenu;
import com.freedom.service.core.SysMenuService;
//import com.freedom.sys.UserUtils;
import com.freedom.util.EasyUITreeNode;
import com.freedom.util.EasyUITreeUtil;
import com.freedom.util.sys.HtmlUtil;
//import com.freedom.util.sys.RedisUtil;
import com.freedom.vo.w.core.WebVo;

/**
 * 菜单controller
 * @author HGJ
 *
 */
@Controller
public class SysMenuController extends BaseWebPaginationCRUDController<WebVo> {
	// 本地异常日志记录对象
	private static final Logger logger = LoggerFactory.getLogger(SysMenuController.class);
	@Autowired
	private SysMenuService sysMenuService;
	
	/**
	 * 菜单列表初始化跳转
	 */
	@Override
	public String init() {
		return null;
	}
	
	/**
	 * 查询当前用户的菜单
	 * @param response
	 */
	@RequiresPermissions("sys:user:view")
	@RequestMapping(value="wh003/wh034")
	public void getUserMenus(HttpServletRequest request,HttpServletResponse response){
		List<EasyUITreeNode> easyUITreeNodes = null;
		try {
			//easyUITreeNodes = (List<EasyUITreeNode>) RedisUtil.get("easyUITreeNodes"+UserUtils.getUserId());
			if(easyUITreeNodes == null){
				List<SysMenu> sysMenus = sysMenuService.getSysMenus();
				easyUITreeNodes = EasyUITreeUtil.getSysMenus(sysMenus);
				//RedisUtil.set("easyUITreeNodes"+UserUtils.getUserId(), easyUITreeNodes);
			}
			logger.info("------读取菜单成功-----");
		} catch (Exception e) {
			logger.error("------读取菜单失败------",e);
		}
		HtmlUtil.writerJson(response, easyUITreeNodes);
	}

}
